#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class School{
	public:
	string schoolName;
	double grade;
	int number;
	public:
	School(string name,double grade,int number){
		schoolName = name;
		this->grade = grade;
		this->number = number;
	}
	bool operator < (const School &sch) const{
		if( (int)this->grade != (int)sch.grade ){
			return (int)this->grade > (int)sch.grade;
		}else if( this->number != sch.number ){
			return this->number < sch.number;
		}else{
			return this->schoolName < sch.schoolName;
		}
		return true;
	}
};
void toLowerCase(string &s){
	for(int i=0; i<s.length(); i++){
		if( s[i] >='A' && s[i]<= 'Z'){
			s[i] = s[i] +('a'-'A');
		}
	}
}
bool cmp(const pair<string,double> &p1,const pair<string,double> &p2){
	return p1.first < p2.first;
}
int main(){
	freopen("in.txt","r",stdin);
	int n;
	cin >> n;
	vector<pair<string,double> > schools; 
	for(int i=0; i<n; i++){
		string id,schoolName;
		double grade;
		cin >> id >> grade >> schoolName;
		toLowerCase(schoolName);
		if( id[0] == 'T' ) grade = grade * 1.5;
		else if( id[0] == 'B' ) grade = grade /1.5;
		schools.push_back(make_pair(schoolName,grade));
	}
	sort(schools.begin(),schools.end(),cmp);
	vector<School> v;
	int cnt = 0;
	double grade = 0;
	grade += schools[0].second;
	cnt++;
	for(int i=1; i<schools.size(); i++){
		if(schools[i].first == schools[i-1].first){
			grade += schools[i].second;
			cnt++;
		}else{
			v.push_back(School(schools[i-1].first,grade,cnt));
			grade = 0;
			cnt = 0;
			grade += schools[i].second;
			cnt++;
		}
	}
	v.push_back(School(schools[schools.size()-1].first,grade,cnt));
	sort(v.begin(),v.end());
	cout << v.size() << endl;
	int oldRank = 0,oldScore = -1;
	for(int i=0; i<v.size(); i++){
		if((int)v[i].grade == oldScore ){
			cout << oldRank << " ";
		}else{
			cout << i+1 << " ";	
			oldRank = i + 1;
			oldScore = (int)v[i].grade;
		} 
		cout << v[i].schoolName << " "<< (int)v[i].grade << " " <<  v[i].number << endl;
	}
}
